package com.sailfish.springbootdemo.dao.db1;

import com.sailfish.springbootdemo.common.DB1TableName;
import com.sailfish.springbootdemo.pojo.db1.RoadmapBigType;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface RoadmapBigTypeDao {

    /**
     * 查询
     *
     * @param searchValue
     * @return
     */
    @Results(id = "roadmapBigTypeResultMap", value = {
            @Result(column = "roadmap_big_type_id", property = "roadmapBigTypeId", jdbcType = JdbcType.INTEGER),
            @Result(column = "roadmap_big_type_name", property = "roadmapBigTypeName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
    })
    @Select("<script>" +
            " select * from " + DB1TableName.ROADMAP_BIG_TYPE + " where 1 = 1 " +
            "<if test='searchValue != null and searchValue != \"\" '>" +
            " and (roadmap_big_type_name like CONCAT('%',#{searchValue},'%'))" +
            "</if>" +
            " order by sort" +
            "</script>")
    List<RoadmapBigType> getAllRoadmapBigType(@Param("searchValue") String searchValue);

    @ResultMap(value = "roadmapBigTypeResultMap")
    @Select("select * from " + DB1TableName.ROADMAP_BIG_TYPE + " where roadmap_big_type_id = #{roadmapBigTypeId}")
    RoadmapBigType getRoadmapBigTypeById(@Param("roadmapBigTypeId") Integer roadmapBigTypeId);

    /**
     * 删除
     *
     * @param roadmapBigTypeId
     * @return
     */
    @Delete("delete from " + DB1TableName.ROADMAP_BIG_TYPE + " where roadmap_big_type_id = #{roadmapBigTypeId}")
    Integer deleteRoadmapBigType(@Param("roadmapBigTypeId") Integer roadmapBigTypeId);

    /**
     * 新增
     *
     * @param roadmapBigType
     * @return
     */
    @Insert("insert into " + DB1TableName.ROADMAP_BIG_TYPE + "(roadmap_big_type_name,status,sort,create_time) values " +
            "(#{roadmapBigType.roadmapBigTypeName},#{roadmapBigType.status},#{roadmapBigType.sort},#{roadmapBigType.createTime})")
    Integer addRoadmapBigType(@Param("roadmapBigType") RoadmapBigType roadmapBigType);

    /**
     * 更新
     *
     * @param roadmapBigType
     * @return
     */
    @Update("<script>" +
            "update " + DB1TableName.ROADMAP_BIG_TYPE +
            "<set>" +
            "<if test='roadmapBigType.roadmapBigTypeName != null and roadmapBigType.roadmapBigTypeName != \"\" '>" +
            " roadmap_big_type_name = #{roadmapBigType.roadmapBigTypeName}," +
            "</if>" +
            "<if test='roadmapBigType.updateTime != null '>" +
            " update_time = #{roadmapBigType.updateTime}," +
            "</if>" +
            "<if test='roadmapBigType.sort != null and roadmapBigType.sort != \"\" '>" +
            " sort = #{roadmapBigType.sort}," +
            "</if>" +
            "<if test='roadmapBigType.status != null and roadmapBigType.status != \"\" '>" +
            " status = #{roadmapBigType.status}," +
            "</if>" +
            "</set>" +
            " where roadmap_big_type_id = #{roadmapBigType.roadmapBigTypeId}" +
            "</script>")
    Integer updateRoadmapBigType(@Param("roadmapBigType") RoadmapBigType roadmapBigType);
}
